var pageii = null;
var grid = null;
$(function() {
	
	grid = lyGrid({
		pagId : 'paging',
		l_column : [ {
			colkey : "id",
			name : "操作",
			width : "110px",
			renderData : function(rowindex,data, rowdata, column) {
				return "<img class='imgbtn' title='编辑分组' src='" + rootPath + "/images/edit.png' onclick=\"editFun('"+data+"')\"/>&nbsp;&nbsp;&nbsp;&nbsp;" +
						"<img class='imgbtn' title='查看' src='" + rootPath + "/images/view.png' onclick=\"viewFun('"+data+"')\"/>";
			}
		}, {
			colkey : "name",
			name : "昵称"
		}, {
			colkey : "doctorSex",
			name : "性别",
			renderData : function(rowindex,data, rowdata, column) {
				return data == 0 ? "未知" : (data == 1 ? "男" : "女");
			}
		}, {
			colkey : "hospitalName",
			name : "医院名称"
		}, {
			colkey : "doctorName",
			name : "医生姓名"
		}, {
			colkey : "focusTime",
			name : "关注时间",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
		}, {
			colkey : "groupId",
			name : "分组",
			renderData : function(rowindex,data, rowdata, column) {
				var val = "";
				$.each(group,function(i,e){
					if (e.id == data) {
						val = e.name;
						return false;
					}
				});
				return val;
			}
		}],
		jsonUrl : rootPath + '/wxuser/findByPage.shtml',
		checkbox : true
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		$("input[qt=like]").each(function() {
			if ($(this).val().trim() != "") {
				searchParams[$(this).attr("name")] = "%" + $(this).val().trim() + "%";
			}
		});
		grid.setOptions({
			data : searchParams
		});
	});
	$("#editBatchFun").click("click", function() {
		editBatchFun();
	});
	$("#viewFun").click("click", function() {
		viewFun();
	});
});
function editFun(cbox) {
	pageii = layer.open({
		title : "编辑",
		type : 2,
		area : [ "600px", "200px" ],
		content : [rootPath + '/wxuser/editUI.shtml?id=' + cbox, 'no']
	});
}

function editBatchFun() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择记录项！");
		return;
	}
	pageii = layer.open({
		title : "编辑",
		type : 2,
		area : [ "600px", "200px" ],
		content : [rootPath + '/wxuser/editBatchUI.shtml?ids=' + cbox.join(","), 'no']
	});
}

function viewFun(cbox) {
	pageii = layer.open({
		title : "查看",
		type : 2,
		area : [ "600px", "530px" ],
		content : [rootPath + '/wxuser/viewUI.shtml?id=' + cbox, 'no']
	});
}